﻿using System.Xml.Linq;
using Maple.Weixin.MP.Helpers;

namespace Maple.Weixin.MP.Entities.Messages
{
    public sealed class ResponseMessageText : ResponseMessageBase
    {
        internal ResponseMessageText(string content) : this(content, false) {}

        internal ResponseMessageText(string content, bool encrypt) : base(encrypt) {
            this.Content = content;
        }

        public override ResponseMessageType MessageType
        {
            get { return ResponseMessageType.Text; }
        }

        private string content;

        public string Content {
            get { return content ?? ""; }
            private set { content = value; }
        }

        public override XDocument ToXDocumentBase()
        {
            var document = new XDocument(
                new XElement("xml",
                             new XElement("ToUserName", new XCData(ToUserName)),
                             new XElement("FromUserName", new XCData(FromUserName)),
                             new XElement("CreateTime", WeixinHelper.GetWeixinDateTime(CreateTime)),
                             new XElement("MsgType", new XCData(MessageType.ToString().ToLower())),
                             new XElement("Content", new XCData(Content))
                    ));

            return document;
        }
    }
}
